home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / cstdio.arc / SRC.ARC / KBDIO.A < prev    next >
Text File  |  1985-08-21  |  4KB  |  241 lines

  1. ;    kbdio.a - keyboard functions.
  2. ;    (C) Copyright 1985 Cray Research Inc. - All Rights Reserved.
  3. ;    G. R. Mansfield.  85/07/18.
  4. ;    Ver 1.0-5821.
  5.  
  6.  
  7.     include    "include/ascii.ah"
  8.     include    "include/kbdio.ah"
  9.     include    "include/msdos.ah"
  10.  
  11. ;    ROM-BIOS interrupts.
  12.  
  13. I_CTC    equ    023h        ; Control-C interrupt
  14. I_PRS    equ    005h        ; print screen interrupt
  15.  
  16. I_KR    equ    016h        ; keyboard request interrupt
  17. KR_RC    equ    0        ; read character
  18. KR_KS    equ    1        ; keyboard status
  19.     
  20.  
  21.     dseg
  22.  
  23. ;    Local data.
  24.  
  25. ;    KCT - Keyboard character conversion table.
  26.  
  27. kct:
  28.     db    0
  29.     dw    KBD_CBK
  30.     db    59
  31.     dw    KBD_F1
  32.     db    60
  33.     dw    KBD_F2
  34.     db    61
  35.     dw    KBD_F3
  36.     db    62
  37.     dw    KBD_F4
  38.     db    63
  39.     dw    KBD_F5
  40.     db    64
  41.     dw    KBD_F6
  42.     db    65
  43.     dw    KBD_F7
  44.     db    66
  45.     dw    KBD_F8
  46.     db    67
  47.     dw    KBD_F9
  48.     db    68
  49.     dw    KBD_F10
  50.     db    71
  51.     dw    KBD_HM
  52.     db    72
  53.     dw    KBD_UP
  54.     db    73
  55.     dw    KBD_PU
  56.     db    75
  57.     dw    KBD_LF
  58.     db    77
  59.     dw    KBD_RT
  60.     db    79
  61.     dw    KBD_ED
  62.     db    80
  63.     dw    KBD_DN
  64.     db    81
  65.     dw    KBD_PD
  66.     db    82
  67.     dw    KBD_IN
  68.     db    83
  69.     dw    KBD_DL
  70.     db    114
  71.     dw    KBD_CPS
  72.     db    115
  73.     dw    KBD_CLF
  74.     db    116
  75.     dw    KBD_CRT
  76.     db    117
  77.     dw    KBD_CED
  78.     db    119
  79.     dw    KBD_CHM
  80.     db    120
  81.     dw    KBD_A1
  82.     db    121
  83.     dw    KBD_A2
  84.     db    122
  85.     dw    KBD_A3
  86.     db    123
  87.     dw    KBD_A4
  88.     db    124
  89.     dw    KBD_A5
  90.     db    125
  91.     dw    KBD_A6
  92.     db    126
  93.     dw    KBD_A7
  94.     db    127
  95.     dw    KBD_A8
  96.     db    128
  97.     dw    KBD_A9
  98.     db    129
  99.     dw    KBD_A0
  100.     db    253
  101.     dw    KBD_CBK
  102.     db    254
  103.     dw    KBD_PS
  104. kcta    db    0
  105.     dw    -1         ; illegal character
  106.  
  107. ccv    dw    0,0        ; Control-C interrupt vector
  108. psv    dw    0,0        ; PrtSc interrupt vector
  109.  
  110.  
  111. ;    Public data.
  112.  
  113.     public    kbd_kc_
  114.  
  115. kbd_kc_    dw    0        ; keyboard character
  116.  
  117.  
  118.     cseg
  119. ki    dw    0        ; keyboard input (e.g. from an interrupt)
  120.  
  121. ;    Public functions.
  122.  
  123.     public    kbd_bgn_
  124.     public    kbd_end_
  125.     public    kbd_getc_
  126.     public    kbd_csts_
  127.  
  128.  
  129. ;    int kbd_getc()    /* console input */
  130.  
  131. kbd_getc_:
  132. gtc:    cmp    ki,0
  133.     jnz    gtc5        ; if keyboard input preset
  134.     mov    ah,KR_RC    ; read keyboard character
  135.     push    bp
  136.     int    I_KR
  137.     pop    bp
  138. gtc1:    mov    kbd_kc_,ax
  139.     cmp    al,0
  140.     jz    gtc3        ; if extended character set
  141.     mov    ah,0
  142.     cmp    al,CV_CR    ; convert CR to '\n'
  143.     jnz    gtc2
  144.     mov    al,CV_LF
  145. gtc2:    ret
  146.  
  147. gtc3:    mov    si,offset kct-2    ; look up character
  148.     mov    kcta,ah
  149. gtc4:    inc    si        ; skip conversion
  150.     inc    si
  151.     lodsb
  152.     cmp    al,ah
  153.     jnz    gtc4
  154.     lodsw            ; get conversion
  155.     ret
  156.  
  157. gtc5:    xor    ax,ax        ; clear character and process
  158.     xchg    ax,ki
  159.     jmp    gtc1
  160.  
  161.  
  162. ;    int kbd_csts()    /* keyboard status, return character if any available,
  163. ;        else return 0 */
  164.  
  165. kbd_csts_:
  166.     cmp    ki,0
  167.     jnz    gtc        ; if character preset
  168.     mov    ah,KR_KS
  169.     push    bp
  170.     int    I_KR
  171.     pop    bp
  172.     jnz    gtc        ; keyboard input available
  173.     xor    ax,ax
  174.     ret
  175.  
  176.  
  177. ;    kbd_bgn(cf)    /* begin interrupt processing */
  178. ;    boolean cf;
  179.  
  180. kbd_bgn_:
  181.     mov    bx,sp        ; check Control-C flag
  182.     mov    ax,[bx+2]
  183.     push    es
  184.     or    ax,ax
  185.     jnz    bgn1        ; if set to allow interrupt to halt program
  186.     mov    ax,(FR_GIV*256) + I_CTC  ; replace Control-C interrupt
  187.     int    I_FCN
  188.     mov    ccv,bx
  189.     mov    ccv+2,es
  190.     mov    dx,offset cci
  191.     push    ds
  192.     push    cs
  193.     pop    ds
  194.     mov    ax,(FR_SIV*256) + I_CTC
  195.     int    I_FCN
  196.     pop    ds
  197. bgn1:    mov    ax,(FR_GIV*256) + I_PRS  ; replace print screen interrupt
  198.     int    I_FCN
  199.     mov    psv,bx
  200.     mov    psv+2,es
  201.     mov    dx,offset psi
  202.     push    ds
  203.     push    cs
  204.     pop    ds
  205.     mov    ax,(FR_SIV*256) + I_PRS
  206.     int    I_FCN
  207.     pop    ds
  208.     pop    es
  209.     ret
  210.  
  211.  
  212. ;    kbd_end()    /* end keyboard processing */
  213.  
  214. kbd_end_:
  215.     mov    ax,ccv        ; check Control-C interrupt
  216.     add    ax,word ccv+2
  217.     jz    end1        ; if not set
  218.     push    ds        ; restore Control-C interrupt
  219.     lds    dx,ccv
  220.     mov    ax,(FR_SIV*256) + I_CTC
  221.     int    I_FCN
  222.     pop    ds
  223. end1:    push    ds        ; restore print screen interrupt
  224.     lds    dx,psv
  225.     mov    ax,(FR_SIV*256) + I_PRS
  226.     int    I_FCN
  227.     pop    ds
  228.     ret
  229.  
  230.  
  231. ;    CCI - Control-C interrupt processor.
  232.  
  233. cci:    mov    word ki,CV_ETX    ; set Control-C character
  234.     iret
  235.  
  236.  
  237. ;    PSI - PrtSc interrupt processor.
  238.  
  239. psi:    mov    word ki,0FE00h    ; set PrtSc character
  240.     iret
  241.